﻿using Microsoft.Extensions.Options;
using Quartz.Logging;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zhao.Common.AliyunUtil.Model;
using Zhao.Common.Helper;
using Zhao.IServer;
using Zhao.IServer.Log;
using Zhao.Models.Entity;
using Zhao.Repository.Base;
using Zhao.Repository.UnitOfWork;

namespace Zhao.Service.Log
{
    /// <summary>
    /// 日志
    /// </summary>
    public class LogsServer : BaseService<Logs>, ILogsServer
    {
        private readonly IUnitOfWork _unitOfWork;
        private readonly LogConfigModel logConfigModel;
        public LogsServer(IBaseRepository<Logs> baseDal, IUnitOfWork unitOfWork, IOptionsSnapshot<LogConfigModel> options) : base(baseDal, unitOfWork)
        {
            _unitOfWork = unitOfWork;
            logConfigModel = options.Value;
        }

        public async Task Debug(string message)
        {
            if (logConfigModel.Debug)
            {
                await _baseDal.AddAsync(new Logs
                {
                    LogContent=message,
                    LogLevel= "Debug",
                    CreatedAt= DateTime.Now,
                });
            }
        }

        public async Task Error(string message)
        {
            if (logConfigModel.Error)
            {
                await _baseDal.AddAsync(new Logs
                {
                    LogContent = message,
                    LogLevel = "Error",
                    CreatedAt = DateTime.Now,
                });
            }
        }

        public async Task Fatal(string message)
        {
            if (logConfigModel.Error)
            {
                await _baseDal.AddAsync(new Logs
                {
                    LogContent = message,
                    LogLevel = "Fatal",
                    CreatedAt = DateTime.Now,
                });
            }
        }

        public async Task Info(string message)
        {
            if (logConfigModel.Error)
            {
                await _baseDal.AddAsync(new Logs
                {
                    LogContent = message,
                    LogLevel = "Info",
                    CreatedAt = DateTime.Now,
                });
            }
        }

        public async Task Trace(string message)
        {
            if (logConfigModel.Error)
            {
                await _baseDal.AddAsync(new Logs
                {
                    LogContent = message,
                    LogLevel = "Trace",
                    CreatedAt = DateTime.Now,
                });
            }
        }

        public async Task Warn(string message)
        {
            if (logConfigModel.Error)
            {
                await _baseDal.AddAsync(new Logs
                {
                    LogContent = message,
                    LogLevel = "Warn",
                    CreatedAt = DateTime.Now,
                });
            }
        }
    }
}
